package com.wc.算法提高课.D第四章_高级数据结构.树状数组.一个简单的整数问题2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/16 23:28
 * @description https://www.acwing.com/problem/content/description/244/
 */
public class Main {
    /**
     * sum[x] = sum[a[1 ~ x]]
     * sum[x]
     * = b1 + b1 + b2 + b1 + b2 + b3 + ... + b1 + ... + bx
     * = x * b1 + (x - 1) * b2 + ... + bx
     * = (x + 1) * (b1 + b2 + ... + bx) - (b1 + 2 * b2 + 3 * b3 + ... + x * bx)
     * = (x + 1) * sum(b[1 ~ x]) - sum(i * b[1 ~ x])
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static final int N = 100010;
    // tr1[i] mean sum(b[1 ~ i])    tr2[i] mean sum(i * b[1 ~ i])
    static long[] tr1 = new long[N], tr2 = new long[N];
    static int[] a = new int[N];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            long b = a[i] - a[i - 1];
            add(tr1, i, b);
            add(tr2, i, i * b);
        }
        while (m-- > 0) {
            String op = sc.next();
            int l = sc.nextInt(), r = sc.nextInt();
            if (op.equals("C")) {
                int d = sc.nextInt();
                add(tr1, l, d);
                add(tr1, r + 1, -d);
                add(tr2, l, (long) l * d);
                add(tr2, r + 1, (long) (r + 1) * -d);
            } else {
                out.println(prefixSum(r) - prefixSum(l - 1));
            }
        }
        out.flush();
    }

    static int lowbit(int x) {
        return x & -x;
    }

    static void add(long[] tr, int x, long c) {
        for (int i = x; i <= n; i += lowbit(i)) tr[i] += c;
    }

    static long sum(long[] tr, int x) {
        long res = 0;
        for (int i = x; i > 0; i -= lowbit(i)) res += tr[i];
        return res;
    }

    static long prefixSum(int x) {
        return (x + 1) * sum(tr1, x) - sum(tr2, x);
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
